//
//  WelfareActivityCenterTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/8/10.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "WelfareActivityCenterTableViewCell.h"
#import "WaveSchedule.h"

@interface WelfareActivityCenterTableViewCell ()

@property (strong, nonatomic) UIView *cornerBgView;
@property (strong, nonatomic) UIImageView *iconIV;
@property (strong, nonatomic) UILabel *nameL;
@property (strong, nonatomic) UILabel *desL;
@property (strong, nonatomic) UIImageView *goCompleteView;
@property (strong, nonatomic) UILabel *goCompleteL;
@property (strong, nonatomic) UILabel *proportionLabel;


@property (strong ,nonatomic)WaveSchedule *waveView;

@end

@implementation WelfareActivityCenterTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.waveView =  [[WaveSchedule alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-jisuan(70), 0, jisuan(100), jisuan(40))];
        MKViewBorderRadius(self.waveView, jisuan(20), 1,  [UIColor colorWithHexString:@"9ac9ff"]);
        
        [self.contentView addSubview:self.cornerBgView];
        [self.contentView addSubview:self.iconIV];
        [self.contentView addSubview:self.nameL];
        [self.contentView addSubview:self.desL];
        [self.contentView addSubview:self.goCompleteView];
        [self.contentView addSubview:self.waveView];
        [self.contentView addSubview:self.goCompleteL];
        self.goCompleteL.hidden = YES;
        
        
        UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageiiii"]];
        [self.contentView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.iconIV);
            make.top.equalTo(self.iconIV.mas_bottom).offset(-jisuan(20));
            make.size.mas_equalTo(CGSizeMake(jisuan(70), jisuan(30)));
        }];
        
        [self.contentView addSubview:self.proportionLabel];
        [self.proportionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(image);
        }];
        
       
//
//
//        UILabel *label = [[UILabel alloc] init];
//        label.textColor = [UIColor colorWithHexString:@"#9ac9ff"];
//        label.textAlignment = NSTextAlignmentCenter;
//        label.font = Font(20);
//        [self.contentView addSubview:label];
//        [label mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.center.equalTo(self.goCompleteView);
//        }];
        
    }
    
    return self;
}

- (void)setModel:(SmallModel *)model {
    
    self.nameL.text = model.title;
    self.desL.text = model.doc;
    [self.iconIV sd_setImageWithURL:[NSURL URLWithString:model.img]];
    self.proportionLabel.text = model.jiangli;

    switch ([model.button intValue]) {
        case 0:
            {
                self.waveView.hidden = YES;
                self.goCompleteL.hidden = YES;
                self.goCompleteView.hidden = NO;
                self.goCompleteView.image = [UIImage imageNamed:@"quwancehgn"];
            }
            break;
        case 1:
        {
            self.goCompleteView.hidden = YES;
            self.waveView.hidden = NO;
            self.goCompleteL.hidden = NO;
            [self.waveView drawWaterWavePath:[model.start floatValue] / [model.end floatValue]];
        }
            break;
        case 2:
        {
            self.waveView.hidden = YES;
            self.goCompleteL.hidden = YES;
            self.goCompleteView.hidden = NO;
            self.goCompleteView.image = [UIImage imageNamed:@"dailingqu"];
        }
            break;
        case 3:
        {
            self.waveView.hidden = YES;
            self.goCompleteL.hidden = YES;
            self.goCompleteView.hidden = NO;
            self.goCompleteView.image = [UIImage imageNamed:@"yiwancehng"];
        }
            break;
            
        default:
            break;
    }
    
}


- (void)layoutSubviews {

    [super layoutSubviews];

    __weak typeof(self) weakSelf = self;
    [self.cornerBgView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(20));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(20));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(10));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(10));
    }];

    [self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.left.mas_equalTo(weakSelf.cornerBgView.mas_left).with.offset(jisuan(16));
        make.height.mas_equalTo(jisuan(90));
        make.width.mas_equalTo(jisuan(90));
    }];

    [self.goCompleteView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(weakSelf.cornerBgView.mas_right).with.offset(-jisuan(30));
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(100));
        make.height.mas_equalTo(jisuan(40));
    }];
    [self.goCompleteL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.goCompleteView.mas_centerY);
        make.centerX.mas_equalTo(weakSelf.goCompleteView.mas_centerX);
    }];

    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.iconIV.mas_right).with.offset(jisuan(30));
        make.top.mas_equalTo(weakSelf.cornerBgView.mas_top).with.offset(jisuan(42));
        make.right.mas_equalTo(weakSelf.goCompleteView.mas_left).with.offset(-jisuan(20));
        make.height.mas_equalTo(jisuan(28));
    }];

    [self.desL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.iconIV.mas_right).with.offset(jisuan(30));
        make.top.mas_equalTo(weakSelf.nameL.mas_bottom).with.offset(jisuan(14));
        make.right.mas_equalTo(weakSelf.goCompleteView.mas_left).with.offset(-jisuan(20));
        make.bottom.mas_equalTo(-Margin);
    }];
    
    [self.waveView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.goCompleteView);
    }];

}

#pragma mark -lazy
- (UIView *)cornerBgView {
    
    if (!_cornerBgView) {
        
        _cornerBgView = [[UIView alloc] init];
        _cornerBgView.backgroundColor = WhiteColor;
        
        _cornerBgView.layer.cornerRadius = jisuan(16);
        _cornerBgView.layer.borderColor = Colordddddd.CGColor;
        _cornerBgView.layer.borderWidth = jisuan(2);
        _cornerBgView.layer.masksToBounds = YES;
        
    }
    
    return _cornerBgView;
}

- (UIImageView *)iconIV {
    
    if (!_iconIV) {
     
        _iconIV = [[UIImageView alloc] init];
        _iconIV.contentMode = UIViewContentModeScaleAspectFit;
        _iconIV.image = [UIImage imageNamed:@"welfareIconIVExplameBG"];
    }
    
    return _iconIV;
}

- (UILabel *)nameL {
    
    if (!_nameL) {
        
        _nameL = [[UILabel alloc] init];
        _nameL.text = @"购买一件商品";
        _nameL.textColor = Color333333;
        _nameL.font = Font(28);
        _nameL.textAlignment = NSTextAlignmentLeft;
        
        [_nameL sizeToFit];
        
    }
    
    return _nameL;
}
- (UILabel *)desL {
    
    if (!_desL) {
        
        _desL = [[UILabel alloc] init];
        _desL.text = @"去购物中心买一个件商品";
        _desL.textColor = Color999999;
        _desL.numberOfLines = 0;
        _desL.font = Font(20);
        _desL.textAlignment = NSTextAlignmentLeft;
        [_desL sizeToFit];
    }
    
    return _desL;
}

- (UIImageView *)goCompleteView {
    
    if (!_goCompleteView) {
        
        _goCompleteView = [[UIImageView alloc] init];
        _goCompleteView.backgroundColor = WhiteColor;
    }
    return _goCompleteView;
}

- (UILabel *)goCompleteL {
    
    if (!_goCompleteL) {
        
        _goCompleteL = [[UILabel alloc] init];
        _goCompleteL.text = @"进行中";
        _goCompleteL.textColor = Color1f89ff;
        _goCompleteL.font = Font(20);
        _goCompleteL.textAlignment = NSTextAlignmentCenter;
        
    }
    
    return _goCompleteL;
}

- (UILabel *)proportionLabel {
    if (!_proportionLabel) {
        _proportionLabel = [[UILabel alloc] init];
        _proportionLabel.font = Font(15);
        _proportionLabel.text = @"50值";
        _proportionLabel.textColor = WhiteColor;
        _proportionLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _proportionLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
